package com.spirng.leetcode.day07;

import java.util.ArrayList;

public class Test530 {
    public static void main(String[] args) {
        Test530 test530 = new Test530();
        test530.getMinimumDifference(new TreeNode(4,new TreeNode(2,new TreeNode(1),new TreeNode(6)),new TreeNode(6)));

    }
    TreeNode pre;// 记录上一个遍历的结点
    int result = Integer.MAX_VALUE;
    public int getMinimumDifference(TreeNode root) {
      traverse(root);
      return result;
    }
    public void traverse(TreeNode node){
        if(node==null){
            return;
        }
        traverse(node.left);
        if(pre!=null){
            result=Math.min(result,node.val - pre.val);
        }
        pre=node;
        traverse(node.right);
    }
}
